package com.alex.space.commons.jdk.kit8;

import java.util.Objects;
import java.util.function.Predicate;

/**
 * @author Alex
 *         Created by Alex on 2017/12/22.
 *         <p>
 *         Functional API
 */
public class FunctionalDemo {

    public static void run() {

        Converter<String, Integer> converter = Integer::valueOf;
        Integer converted = converter.convert("123");
        System.out.println(converted);

        Converter<Integer, String> stringConverter = (from) -> String.valueOf(from + 1);
        String newStr = stringConverter.convert(2);
        System.out.println(newStr);

        // build-in
        // Predicate
        Predicate<String> predicate = (s) -> s.length() > 0;
        predicate.test("foo");
        predicate.negate().test("foo");
        Predicate<Boolean> nonNull = Objects::nonNull;
        Predicate<Boolean> isNull = Objects::isNull;
        Predicate<String> isEmpty = String::isEmpty;
        Predicate<String> isNotEmpty = isEmpty.negate();

        // Function、Supplier、Consumer、Comparator、Optional。。。
    }
}
